from django.db import models

# Create your models here.


class Goods(models.Model):
	"""商品表"""
	name = models.CharField(max_length=20)
	price = models.FloatField()
	status = models.BooleanField(default=True)
	class Meta:
		db_table = 't_goods'


# Create your models here.
class BookInfo(models.Model):
	name = models.CharField(max_length=10, unique=True, verbose_name='书籍名')
	pub_date = models.DateField(null=True)  # 发布日期
	read_count = models.IntegerField(default=0)  # 阅读数
	comment_count = models.IntegerField(default=0)  # 评论数
	is_delete = models.BooleanField(default=False)  # 是否被逻辑删除

	class Meta:
		db_table = 't_bookinfo'  # 指定模型对应数据库中表的表名
		verbose_name = '书籍信息'  # 修改后台admin显示的表名

	def __str__(self):
		return self.name


# 准备人物列表信息的模型类
class PeopleInfo(models.Model):
	# 性别的可选值 0对应male 1对应female
	GENDER_CHOICES = (
		(0, 'male'),
		(1, 'female')
	)
	name = models.CharField(max_length=20, verbose_name='名称')  # 人物的名字
	gender = models.SmallIntegerField(choices=GENDER_CHOICES, default=0, verbose_name='性别')  # 人物的性别
	description = models.CharField(max_length=200, null=True, verbose_name='描述信息')  # 人物的描述信息
	book = models.ForeignKey(BookInfo, on_delete=models.CASCADE, verbose_name='图书')  # 引用外键，引用的模型为BookInfo
	is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')  # 是否被逻辑删除

	class Meta:
		db_table = 't_peopleinfo'
		verbose_name = '人物信息'

	def __str__(self):
		return self.name

